import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 高生平
 * Date: 2025-09-05
 * Time: 19:48
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println("0~" + n + "之间所有的水仙花数从小到大依次为：");
        for (int i = 0; i <= n; i++) {
            int tmp = i;

            //1.求该数是几位数
            int count = 0;
            while (tmp > 0) {
                count++;
                tmp /= 10;
            }

            //2.求每位count次方的和
            tmp = i;//重置tmp
            int sum = 0;
            while (tmp > 0) {
                sum += Math.pow(tmp % 10, count);
                tmp /= 10;
            }

            //3.验证是否位水仙花数
            if (sum == i) {
                System.out.print(i + " ");
            }
        }
        }
}
